package com.jming.yygh.common.util;

import com.jming.yygh.common.helper.JwtHelper;

import javax.servlet.http.HttpServletRequest;

/**
 * 获取当前用户信息的工具类
 * @author jming
 * @date 2021-04-07a
 */
public class AuthContextHolder {

    /**
     * 获取用户id
     * @param request
     * @Author jming
     * @Date 2021/5/12
     * @return Long
     */
    public static Long getUserId(HttpServletRequest request) {

        // 从header获取token
        String token = request.getHeader("token");

        // jwt从token获取userid
        return JwtHelper.getUserId(token);


    }

    /**
     * 获取用户名称
     * @param request
     * @Author jming
     * @Date 2021/5/12
     * @return Long
     */
    public static String getUserName(HttpServletRequest request) {

        // 从header获取token
        String token = request.getHeader("token");

        // jwt从token获取userName
        return JwtHelper.getUserName(token);


    }

}
